package com.yhsimon.realm.member.service.impl;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.yhsimon.realm.member.constant.ResultCodeEnum;
import com.yhsimon.realm.member.exception.RealmException;
import com.yhsimon.realm.member.service.NewsService;
import com.yhsimon.realm.member.utils.NewsCrawlUtils;
import com.yhsimon.realm.member.vo.news.NewsVo;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NewsServiceImpl implements NewsService {

    @Override
    @SentinelResource(value = "listNews", blockHandler = "blockExceptionHandler")
    public List<NewsVo> listNews() {
        try {
            return NewsCrawlUtils.generateNewsData();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }

    public List<NewsVo> blockExceptionHandler(BlockException e) {
        throw new RealmException(ResultCodeEnum.SYSTEM_BUSY);
    }
}
